<?php
namespace Framework\Library\Validator;

use Phalcon\Validation;
use Phalcon\Validation\Message;
use Framework\Library\Tool;
use Phalcon\Validation\Validator;
use Phalcon\Validation\ValidatorInterface;

class DatetimeValidator extends Validator implements ValidatorInterface
{
    public function validate(Validation $validation, $attribute)
    {
        $datetime = $validation->getValue($attribute);

        if (!Tool::validateDateTime($datetime, $this->getOption('format'))) {
            $validation->appendMessage(new Message('Datetime format error', $attribute, 'Datetime'));

            return false;
        }

        return true;
    }
}
